﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SsrsRenderStudio.Shared
{
    /// <summary>
    /// Parses even number of string arguments into a hashtable.
    /// </summary>
    public class ParameterHash
    {
        public ParameterHash(string[] args)
        {
            BuildHashTable(args);
        }

        private bool BuildHashTable(string[] args)
        {
            if (args == null)
            {
                _table = new System.Collections.Hashtable();
                return true;
            }

            System.Collections.Hashtable hashTable = new System.Collections.Hashtable(args.Length / 2);

            if (args.Length % 2 != 0)
            {
                _table = null;
                return false;
            }
            else
            {
                int i = 0;
                while (i < args.Length - 1)
                {
                    hashTable.Add(args[i], args[i + 1]);
                    i += 2;
                }
                _table = hashTable;
                _table2 = args;

                return true;
            }
        }

        private System.Collections.Hashtable _table;

        public System.Collections.Hashtable Table
        {
            get
            {
                return _table;
            }
        }

        private string[] _table2 = null;

        public string[] Table2
        {
            get
            {
                return _table2;
            }
        }

    }
}
